/*
 * Author : Dspark
 * Time : 11.6,	2011
 * Version : Accepted By ZOJ
 * 算法思想：递归，回溯
终于作出来了，之前的算法还是考虑缺失了，找到的结果不一定是最优的，有时需要回溯才能得到正确答案
下面的测试数据可以检验出先前算法的漏洞
3
...
..X
.X.
（答案应该为4，先前的算法算出来是3，因为没有回溯
3
...
..X
.XX
(答案为3，这个倒是能算出来)
*/


#include<stdio.h>

#define N 4

typedef struct SPosition
{
	int x,y;
}position;

typedef struct SStack
{
	int index;
	position stack[16];
}stack;

typedef struct SMap
{
	int size;
	char map[N][N];
}map;

stack s = {-1};
map m = {0};
int total,hanging = 0;
/*map m = {4,{
				{'.','.','.','.'},
				{'.','.','.','.'},
				{'.','.','.','.'},
				{'.','.','.','.'}
	}
};
map m = {4,{
		{'.','x','.','.'},
		{'.','.','.','.'},
		{'x','x','.','.'},
		{'.','.','.','.'}
	}
};

map m = {3,{
		{'.','.','.'},
		{'.','x','x'},
		{'.','x','x'}
	}
};*/

int util_stack_push(int x,int y)
{
	s.index++;
	s.stack[s.index].x = x;
	s.stack[s.index].y = y;
	return s.index;
}

position* util_stack_pop()
{
	int j = s.index;
	s.index--;
	return &(s.stack[j]);
}

void util_stack_clear()
{
	s.index = -1;
	return;
}

int checkX(int x)
{
	int i;
	for(i=s.index;i>=0; i--)
		if(s.stack[i].x == x)
			return i;
	return -1;
}

int checkY(int y)
{
	int i;
	for(i=s.index;i>=0; i--)
			if(s.stack[i].y == y)
				return i;
	return -1;
}

int checkXNoWall(int xpos,int y)
{
	int _x,	i;
	_x = s.stack[xpos].x;
	i = s.stack[xpos].y;
	for(	;i<y;	i++)
		if(m.map[_x][i] == 'X')
			return 0;
	return 1;
}

int checkYNoWall(int ypos,int x)
{
	int _y,	i;
	_y = s.stack[ypos].y;
	i = s.stack[ypos].x;
	for(	;i<x;	i++)
		if(m.map[i][_y] == 'X')
			return 0;
	return 1;
}

void fireNet(int i, int j)
{
	if(hanging && i==m.size && j==0)
		return;
	if(i==m.size && j==m.size-1)
	{
		if( hanging==0)
		{
			if(total<s.index+1)
				total = s.index+1;
			hanging = 1;

		}
		position* p = util_stack_pop();
		fireNet(p->x+1,p->y);
		return;

	}

	if(i==m.size)
	{
		if(hanging)
		{
			position* p  = util_stack_pop();
			fireNet(p->x+1,p->y);
			return;
		}
		else
		{
			fireNet(0,j+1);
			return;
		}

	}

	if(m.map[i][j]=='X')
		fireNet(i+1,j);
	else if(m.map[i][j]=='.')
	{
		int xpos = 0 , ypos = 0;
		xpos=checkX(i);
		if(xpos	!=	-1)
		{
			if(checkXNoWall(xpos,j))
			{
				fireNet(i+1,j);
				return;
			}
		}

		ypos = checkY(j);
		if(ypos	!=	-1)
		{
			if(checkYNoWall(ypos,i))
			{
				fireNet(i+1,j);
				return;
			}
		}
		hanging = 0;
		util_stack_push(i,j);
		fireNet(i+1,j);
		return;
	}
}

void getMap()
{
	int i,j;
	for(i=0;	i<m.size; i++)
	{
		for(j=0;j<m.size;j++)
			m.map[i][j] = getchar();
		getchar();
	}
}

void clearMap()
{
	int i,j;
	for(i=0; i<m.size; i++)
		for(j=0; j<m.size; j++)
			m.map[i][j] = '\0';
	m.size = 0;
	hanging = 0;
	total = 0;
	util_stack_clear();
}

int main(int argc, char **argv) {
	int i,j;
	while(scanf("%d",&(m.size))!=EOF && m.size>0)
	{
		getchar();
		getMap();
		fireNet(0,0);
		printf("%d\n",total);
		clearMap();
	}
	return 0;
}


